home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ9310.ZIP / DFPP03.ZIP / BUTTON.CPP < prev    next >
C/C++ Source or Header  |  1993-09-27  |  2KB  |  91 lines

  1. // ------------- button.cpp
  2.  
  3. #include "button.h"
  4. #include "desktop.h"
  5.  
  6. Button::Button(const char *lbl, int lf, int tp, DFWindow *par)
  7.                 : TextBox(lf, tp, 1, strlen(lbl)+5, par)
  8. {
  9.     String lb("( ) ");
  10.     lb += lbl;
  11.     lb += " ";
  12.     SetText(lb);
  13.     setting = False;
  14.     setchar = ' ';
  15.     colors.fg =
  16.     colors.sfg =
  17.     colors.ffg =
  18.     colors.hfg = par ? par->ClientFG() : 0; 
  19.     colors.bg =
  20.     colors.sbg =
  21.     colors.fbg =
  22.     colors.hbg = par ? par->ClientBG() : 0;
  23.     shortcutfg = RED;
  24. }
  25.  
  26. void Button::Paint()
  27. {
  28.     if (visible)    {
  29.         (*text)[1] = setting ? setchar : ' ';
  30.         if (isEnabled())
  31.             WriteShortcutLine(0, colors.fg, colors.bg);
  32.         else 
  33.             WriteTextLine(0, colors.hfg, colors.hbg);
  34.     }
  35. }
  36.  
  37. Bool Button::SetFocus()
  38. {
  39.     TextBox::SetFocus();
  40.     desktop.cursor().NormalCursor();
  41.     desktop.cursor().SetPosition(Left()+1, Top());
  42.     desktop.cursor().Show();
  43.     return True;
  44. }
  45.  
  46. void Button::ResetFocus()
  47. {
  48.     TextBox::ResetFocus();
  49.     desktop.cursor().Hide();
  50. }
  51.  
  52. void Button::Keyboard(int key)
  53. {
  54.     if (key == ' ')
  55.         InvertButton();
  56.     else 
  57.         TextBox::Keyboard(key);
  58. }
  59.  
  60. void Button::LeftButton(int mx, int my)
  61. {
  62.     if (ClientRect().Inside(mx,my))
  63.         InvertButton();
  64. }
  65.  
  66. void Button::InvertButton()
  67. {
  68.     if (setting)
  69.         ReleaseButton();
  70.     else
  71.         PushButton();
  72. }
  73.  
  74. void Button::PushButton()
  75. {
  76.     setting = True;
  77.     Paint();
  78. }
  79.  
  80. void Button::ReleaseButton()
  81. {
  82.     setting = False;
  83.     Paint();
  84. }
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.